/**
 *管理主页面相关操作 
 */
namespace('base.admin');
/**
 * 初始化
 */
base.admin.init=function(){
	base.admin.initLayout();
	base.admin.initListener();
};
/**
 * 设置布局
 */
base.admin.initLayout=function(){
	var topHeight = 42;
	var minHeight = 450;
	var height =Math.max(minHeight,$(window).height())-topHeight;
	$('#admin-slider').height(height);
	$('#admin-frame').height(height-10);
};
base.admin.initListener=function(){
	$('#admin-slider ul li a').click(function(){
		$('#admin-slider .active').removeClass('active');
		$(this).addClass('active');
		
		var li = $(this).parent();
		if(li.attr('status')==1){
			base.admin.collapseSubmenu(li);
		}else{
			base.admin.expandSubmenu(li);
		}
	});
};
/**
 * 折叠
 * @param menu li
 */
base.admin.collapseSubmenu=function(li){
	li.attr('status',0);
	li.children('.submenu').slideUp('fast');
};
/**
 * 展开菜单
 * @param menu li
 */
base.admin.expandSubmenu=function(li){
	li.attr('status',1);
	if(li.attr('loaded')==1){
		li.children('.submenu').slideDown('fast');
	}else{
		base.admin.loadSubmenu(li);
	}
};
base.admin.loadSubmenu=function(li){
	var id = li.attr('id');
	$.getJSON('base/menu/menu!fetchSubMenus.action?menuType=admin&id=' + id, function(subMenus) {
		var items = [];
		items.push('<ul class="submenu hide">');
		$.each(subMenus, function(index) {
			var menu = subMenus[index];
			items.push('<li id="'+menu.id+'" hasChild="'+menu.hasChild+'">');
			items.push('<a target="admin-frame" href="'+menu.link+'">');
			items.push('<i class="icon-list-alt"></i>');
			items.push('<span>'+menu.name+'</span>');
			items.push('</a></li>');
		});
		items.push('</ul>');
		li.append(items.join(''));
		li.attr('loaded', 1);
		li.children('.submenu').slideDown('fast');
	});
};